<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>校园助手系统登录</title>
	<meta name="description" content="">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<meta name="robots" content="all,follow">
	<link rel="stylesheet" href="https://www.jq22.com/jquery/bootstrap-4.2.1.css">
	<link rel="stylesheet" href="../../css/style.default.css" id="theme-stylesheet">
	<script src="../../layui/layui.js"></script>

</head>

<body>
	<div class="page login-page">
		<div class="container d-flex align-items-center">
			<div class="form-holder has-shadow">
				<div class="row">
					<!-- Logo & Information Panel-->
					<div class="col-lg-6">
						<div class="info d-flex align-items-center">
							<div class="content">
								<div class="logo">
									<h1>欢迎登录</h1>
								</div>
								<p>校园助手系统</p>
							</div>
						</div>
					</div>
					<!-- Form Panel    -->
					<div class="col-lg-6 bg-white">
						<div class="form d-flex align-items-center">
							<div class="content">


								<form method="post" action="login.html" class="form-validate" id="loginFrom">
									<div class="form-group">
										<input id="login-username" type="text" name="userName" required
											data-msg="请输入用户名" placeholder="用户名" value="1840224174" class="input-material" lay-verify="required|username">
									</div>
									<div class="form-group">
										<input id="login-password" type="password" name="passWord" required
											data-msg="请输入密码" placeholder="密码" class="input-material" lay-verify="required|passwd">
									</div>
									<button onclick="dologin();return false;" id="login" type="submit"
											class="btn btn-primary">登录</button>

									<div style="margin-top: -40px;">
									
										<div class="custom-control custom-checkbox " style="float: right;">
											<input type="checkbox" class="custom-control-input" id="check2">
											<label class="custom-control-label" for="check2">自动登录</label>
										</div>
										<div class="custom-control custom-checkbox " style="float: right;">
											<input type="checkbox" class="custom-control-input" id="check1">
											<label class="custom-control-label" for="check1">记住密码&nbsp;&nbsp;</label>
										</div>
									</div>
								</form>



								<br />
								<small>没有账号?</small><a href="../register/register.html" class="signup">&nbsp;注册</a>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- JavaScript files-->
	<script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script>
	<script src="https://www.jq22.com/jquery/bootstrap-3.3.4.js"></script>
	<script src="../../vendor/jquery-validation/jquery.validate.min.js"></script>
	<!--表单验证-->
	<script src="js/jquery.min.js"></script>
		<script src="js/bootstrap.min.js"></script>
		<script src="js/jquery.cookie.js"></script>
		<script src="js/jquery.validate.min.js"></script><!--表单验证-->
		<!-- Main File-->
		<!-- <script src="js/front.js"></script> 
	<!-- Main File-->
	<script src="../../js/front.js"></script>
	<script src="../../js/jquery.cookie.js"></script>
	<script src="../login2/login.js"></script>
	<script>
		
		
		//-------------------------------------------------

		layui.use('layer', function () {
			layer = layui.layer;
			$ = layui.jquery;

			// 获取焦点
			$('#login-username').focus();

			// 直接回车登录
			$('input').keydown(function (e) {
				if (e.keyCode == 13) {
					dologin();
				}
			});
		});

		//登录
		function dologin() {
			var usrture =/^\d{10}$/
			//教师工号判断
			var usrtures =/^\d{4}$/
			var num=usrture.test(username);
			var nums=usrtures.test(username);
			var username = $.trim($('#login-username').val());
			var password = $('#login-password').val();

			if (username == '') {
				layer.alert('请输入用户名', { 'icon': 2 });
				return;
			}
			if (password == '') {
				layer.alert('密码不能为空', { 'icon': 2 });
				return;
			}
			// $.post('http://127.0.0.1:8000/dologin',{'username':username,'password':password},function(res){
			// 	if(res.code>0){
			// 		layer.alert(res.msg,{'icon':2});
			// 	}else{
			// 		layer.msg(res.msg);
			// 		setTimeout(function(){location.href='./layui-admin/index'},1000);
			// 	}
			// },'json');
			
			
			$.ajax({
				url: "http://127.0.0.1:8000/dologin",
				type: "post",
				dataType: "JSON",
				data: { "username": username, "password": password },
				success: function (res) {
					if (res.code == 1) {
						layer.msg(res.msg);
					}
					if (res.code == 0) {
						layer.msg(res.msg);
						setTimeout(function () { 
							localStorage.setItem("admin", username);
							localStorage.setItem("psw", password);
							localStorage.setItem("identity", "admin");
							localStorage.setItem("username", res.username);
							localStorage.setItem("userAvatar", res.userImg);
							console.log(res.username)
							localStorage.setItem("userInfo", res); 
							localStorage.setItem("userBirthday", res.userBirthday);
							window.location.href = '../../index.html' 
						    
						}, 1000);
					}
					if (res.code == 2) {
						layer.msg(res.msg);
						setTimeout(function () { 
							localStorage.setItem("admin", username);
							localStorage.setItem("psw", password);
							localStorage.setItem("identity","student");
							localStorage.setItem("username", res.username);
							localStorage.setItem("userAvatar", res.userImg);
							localStorage.setItem("phone", res.phone);
							localStorage.setItem("email", res.email);
							localStorage.setItem("userBirthday", res.userBirthday);
							localStorage.setItem("userInfo", res); 
							window.location.href = '../../index.html' 
						    
						}, 1000);
					}
					if (res.code == 3) {
						layer.msg(res.msg);
						setTimeout(function () {
							localStorage.setItem("userInfo", res); 
							localStorage.setItem("admin", username);
							localStorage.setItem("psw", password);
							localStorage.setItem("identity", "teacher");
							localStorage.setItem("username", res.username);
							localStorage.setItem("userAvatar", res.userImg);
							localStorage.setItem("userBirthday", res.userBirthday);
							window.location.href = '../../index.html' 
						    
						}, 1000);
					}
					if (res.code == 4) {
						layer.msg(res.msg);
						
					}
				}
			})

		}
	</script>
</body>

</html>